home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK2.toast / Development Kits (Disc 2) / QuickTime™ IC SDK 1.01 / Sample Code / QTICSampleApp / Sources / main.c < prev    next >
Encoding:
Text File  |  1997-06-06  |  3.9 KB  |  169 lines  |  [TEXT/CWIE]

  1. //========================================================================
  2. // Application:        QTICSampleApp
  3. //
  4. // Description:        This application demonstrates the integration of
  5. //                    QuickTime™ IC functionality.
  6. //
  7. // Author:            Mike Bitz
  8. //                     Developer Technical Support
  9. //                     Apple Computer, Inc.
  10. //
  11. // History:            25-Apr-97 original development (mwb)
  12. //
  13. // Copyright © 1997 Apple Computer, Inc., All Rights Reserved
  14. //
  15. // You may incorporate this sample code into your applications without
  16. // restriction, though the sample code has been provided "AS IS" and the
  17. // responsibility for its operation is 100% yours.  However, what you are
  18. // not permitted to do is to redistribute the source as "DSC Sample Code"
  19. // after having made changes. If you're going to re-distribute the source,
  20. // we require that you make it clear in the source that the code was
  21. // descended from Apple Sample Code, but that you've made changes.
  22. //========================================================================
  23.  
  24.  
  25. #include "prototypes.h"
  26. #include "application.h"
  27. #include "globals.h"
  28. #include <QTIC.h>
  29.  
  30. extern QTICControls                            gCameraControls;
  31. extern QTICActionFilterWithRefConUPP         gCallBack;
  32.  
  33. //================= Main =================
  34. void main (void) 
  35. {
  36.     InitMac ();
  37.     InitQTIC ();
  38.     SetupMenus ();
  39.     MainEventLoop ();
  40. }
  41.  
  42. //================= InitMac =================
  43. void InitMac (void) 
  44. {
  45.     OSErr        err = noErr;
  46.     THz            curZone;
  47.  
  48.     // Expand the application heap zone
  49.     MaxApplZone ();
  50.     curZone = GetZone();
  51.     if ( curZone->moreMast < kMasterBlockSize ) {
  52.         curZone->moreMast = kMasterBlockSize;
  53.         MoreMasters();
  54.     }
  55.  
  56.     InitGraf (&qd.thePort);
  57.     InitFonts ();
  58.     InitWindows ();
  59.     InitMenus ();
  60.     TEInit ();
  61.     InitDialogs (0L);
  62.     InitCursor ();
  63.     FlushEvents (0, everyEvent);
  64.     
  65.     err = EnterMovies ();
  66.     if (err != noErr)
  67.         SysBeep (1);
  68. }
  69.  
  70. //================= MainEventLoop =================
  71. void MainEventLoop (void)
  72. {        
  73.     OSErr                    err = noErr;
  74.     EventRecord                event;
  75.     Boolean                    ignored;
  76.     
  77.     while (gDone == false)
  78.     {
  79.         ignored = WaitNextEvent (everyEvent, &event, 0, nil);
  80.         DoEvent (&event);
  81.     }
  82.     
  83.     // Dispose QTIC stuff
  84.     if (gCameraControls != nil && gCallBack != nil) 
  85.     {
  86.         // Dispose action filter.
  87.         err = QTICCRemoveActionFilter (gCameraControls, gCallBack, 0);
  88.         DisposeRoutineDescriptor (gCallBack);
  89.  
  90.         err = CloseComponent (gCameraControls);
  91.         gCameraControls = nil;
  92.     }
  93. }
  94.  
  95. //================= DoEvent =================
  96. void DoEvent (EventRecord *eventPtr) 
  97. {
  98.     OSErr                        err = noErr;
  99.     char                        theChar;
  100.     Boolean                     gotEvent = false;
  101.     WindowPtr                    theWindow = nil;
  102.     
  103.     // QTIC event handling
  104.     if (gCameraControls != nil) 
  105.     {
  106.         if (QTICCEvent (gCameraControls, eventPtr)) 
  107.         {
  108.             // This event was handled by QTIC, so update the panel menu accordingly.
  109.             UpdatePanelSpecificMenu ();
  110.             
  111.             // Disable the Close Window menu item if that QTIC event caused the last
  112.             // window to close.
  113.             UpdateCloseWindowItem ();
  114.         } 
  115.         else
  116.         {
  117.             // Give idle time to all panels
  118.             QTICCIdle (gCameraControls);
  119.         }
  120.     }
  121.  
  122.     // Handle standard events
  123.     switch (eventPtr->what) 
  124.     {
  125.         case mouseDown: 
  126.             HandleMouseDown (eventPtr);
  127.             break;
  128.             
  129.         case keyDown:
  130.         case autoKey:
  131.             theChar = eventPtr->message & charCodeMask;
  132.             if ((eventPtr->modifiers & cmdKey) != 0) 
  133.             {
  134.                 HandleMenuChoice (MenuKey (theChar));
  135.             }
  136.             break;
  137.     }
  138. }
  139.  
  140. //================= HandleMouseDown =================
  141. void HandleMouseDown (EventRecord *eventPtr) 
  142. {
  143.     WindowPtr                theWindow = nil, frontWindow = nil;
  144.     short                    thePart;
  145.     long                    menuChoice;
  146.     MenuHandle                hFileMenu = nil;
  147.     
  148.     thePart = FindWindow (eventPtr->where, &theWindow);
  149.     switch (thePart) 
  150.     {
  151.         case inMenuBar:
  152.             menuChoice = MenuSelect (eventPtr->where);
  153.             HandleMenuChoice (menuChoice);
  154.             break;
  155.             
  156.         case inSysWindow: 
  157.             SystemClick (eventPtr, theWindow);
  158.             break;
  159.             
  160.         case inDrag : 
  161.             DragWindow (theWindow, eventPtr->where, &qd.screenBits.bounds);
  162.             break;
  163.             
  164.         case inContent:
  165.             if (theWindow != FrontWindow ())
  166.                 SelectWindow (theWindow);
  167.             break;
  168.     }
  169. }